feat: forward rawRequest and disconnect AbortSignal into onCallGenkit…#1891
Open
IzaakGough wants to merge 2 commits into
Open
feat: forward rawRequest and disconnect AbortSignal into onCallGenkit…#1891IzaakGough wants to merge 2 commits into
IzaakGough wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces CALLABLE_RAW_REQUEST and CALLABLE_RESPONSE_SIGNAL symbols to expose the underlying raw request and abort signal within the Genkit action context in onCallGenkit. Corresponding tests were added to ensure these values are correctly forwarded and that the abort signal functions as expected upon client disconnection. Feedback was provided to use optional chaining when accessing the response signal to avoid potential runtime errors in environments where the response object might be missing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1888
Expose the underlying callable raw request and a client-disconnect
AbortSignalto Genkit actions invoked viahttps.onCallGenkit, so Genkit flows can read request-level details and reliably stop work when the client disconnects (especially for SSE streaming).Changes
src/common/providers/https.ts:src/v2/providers/https.tsso callers can reference the same symbol instances.onCallGenkitto populate the Genkit action context for both JSON and streaming callables:Why
res.signalprovides a standardAbortSignalthat aborts when the client disconnects.Tests
Updated
spec/v2/providers/https.spec.tsto verify:rawRequestandAbortSignalare forwarded into Genkit context for JSON requests.AbortSignalis aborted when the client disconnects (req.emit("close")), and the handler stops accordingly.Usage
Inside a Genkit action invoked via
https.onCallGenkit, read:opts.context[https.CALLABLE_RAW_REQUEST](Express Request)opts.context[https.CALLABLE_RESPONSE_SIGNAL](AbortSignal)Verification
Before the fix
Before the fix running the MRE produces the following logs:
These continue until:
Known Limitation / Follow-Up
There is still an underlying timing/race issue around disconnect vs. in-flight work completion
It appears to be governed by upstream behavior (request/stream lifecycle and/or Genkit action execution), and isn’t something we can reliably fix within firebase-functions alone; addressing it likely requires changes in the upstream caller/runtime (or Genkit).